﻿package cn.antscript.airCMS.display.component 
{
	import com.bit101.components.Label;
	import com.bit101.components.ProgressBar;
	import com.bit101.components.PushButton;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	/**
	 * ...
	 * @author antscript
	 */
	public class SurePanel extends Sprite
	{
		
		
		private static var _instance:SurePanel;
		
		
		private var _label:Label;
		
		private var _sure:PushButton;
		private var _cancel:PushButton;
		
		private var _complete:Function;
		
		public function SurePanel(privateClass:PrivateClass) 
		{
			 _label = new Label(this);
			 
			_label.autoSize = true;
			
			_sure = new PushButton(this, 0, 0, "确定", hideSure);
			_cancel = new PushButton(this, 0, 0, "取消", hideCancel);
			
		}
		
		public static function getInstance():SurePanel {
			if (_instance == null) {
				_instance = new SurePanel(new PrivateClass);
			}
			return _instance;
		}
		
		public function show(alert:String,container:DisplayObjectContainer,com_:Function):void {
			
			_complete = com_;
			
			container.addChild(SurePanel.getInstance());			
			
			container.stage.addEventListener(Event.RESIZE, onResize);
			
			_label.text = alert;
			_label.draw();
			
			onResize();
		}
		public function hideSure(e:MouseEvent=null):void {
			
			this.parent.stage.removeEventListener(Event.RESIZE, onResize);
			this.parent.removeChild(this);
			
			_complete();
			_complete = null;
			
		}		
		public function hideCancel(e:MouseEvent=null):void {
			
			this.parent.stage.removeEventListener(Event.RESIZE, onResize);
			this.parent.removeChild(this);
			
			_complete = null;
		}		
		
		private function onResize(e:Event=null):void 
		{
			graphics.clear();
			graphics.beginFill(0x333333, 0.9);
			graphics.drawRect(0, 0, this.parent.stage.stageWidth, this.parent.stage.stageHeight);
			graphics.endFill();
			
			
			
			
			_label.x = (this.parent.stage.stageWidth - _label.width) / 2;
			_label.y = this.parent.stage.stageHeight / 2;
			
			_sure.x = (this.parent.stage.stageWidth - _sure.width) / 2-80;
			_sure.y = this.parent.stage.stageHeight / 2 + 40;
			
			_cancel.x = (this.parent.stage.stageWidth - _cancel.width) / 2+80;
			_cancel.y = this.parent.stage.stageHeight / 2+40;
		}
		
		
		
	}

}

class PrivateClass {
	
}